package com.stone.back.order.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.stone.back.order.dao.IOrderDao;
import com.stone.back.order.entity.BfOrder;
import com.stone.back.order.entity.BfOrderInfo;
import com.stone.base.entity.Page;
import java.util.Collections;
import java.util.List;

/**
 * 订单管理
 * @author Stone P
 *
 */
@Service
public class OrderService implements IOrderService {
	@Autowired
	private IOrderDao orderDao;

	/**
	 * 查询订单分页信息
	 * @param pageNumber			页数
	 * @param priceMin				订单总价
	 * @param priceMax				订单总价
	 * @param startCreateDate		订餐时间
	 * @param endCreateDate			订餐时间
	 * @param status				订单状态
	 * @return
	 */
	@Override
	public Page selectOrderPage(int pageNumber, String priceMin, String priceMax, String startCreateDate, String endCreateDate, String status) {
		return this.orderDao.selectOrderPage(pageNumber, priceMin, priceMax, startCreateDate, endCreateDate, status);
	}
	
	/**
	 * 查询订单详情分页信息
	 * @param pageNumber	页数
	 * @param orderId		订单Id
	 * @param name			名称
	 * @param datatype		类型
	 * @param priceMax		单价
	 * @param priceMin		单价	
	 * @return
	 */
	@Override
	public Page selectOrderInfoPage(int pageNumber, String orderId, String datatype, String name, String priceMin, String priceMax) {
		return this.orderDao.selectOrderInfoPage(pageNumber, orderId, datatype, name, priceMin, priceMax);
	}

	/**
	 * 查询订单详情
	 * @param orderId	订单Id
	 * @return
	 */
	@Override
	public BfOrder selectOrderDetail(String orderId) {
		BfOrder order = this.orderDao.selectOrderDetail(orderId);
		return order;
	}
        
        /**
         * 查询用户的订单
         * @param userid
         * @return 
         */
        @Override
        public Page selectOrderByUserId(int pageNumber, Integer userid) {
            if(pageNumber <= 0) pageNumber = 1;
            if(userid == null)
                return new Page();
            return this.orderDao.selectOrderByUserId(pageNumber, userid);
        }
        
        /**
         * 查询订单项
         * @param oid
         * @return 
         */
        @Override
        public List<BfOrderInfo> selectOrderInfoByOrderId(String oid) {
            if(oid == null)
                return Collections.emptyList();
            return this.orderDao.selectOrderInfoByOrderId(oid);
        }

	/**
	 * 修改订单信息
	 * @param order	订单信息
	 * @return
	 */
	@Override
	public void updateOrder(BfOrder order) {
		this.orderDao.updateOrder(order);
	}
}
